package com.shujia.json;

import com.google.gson.Gson;

public class Demo1Gson {
    public static void main(String[] args) {


        // \  转义
        String jsonstr = "{\"id\":\"1500100001\",\"age\":22,\"gender\":\"女\",\"clazz\":\"文科六班\"}";


        //使用Gson解析json字符串
        Gson gson = new Gson();

        //gon内部使用反射实现的
        Student student = gson.fromJson(jsonstr, Student.class);

        System.out.println(student);


        //将java中的对象转换成json字符串
        Student student1 = new Student("001", "张三", 23, "男", "一班");


        String toJson = gson.toJson(student1);

        System.out.println(toJson);


    }
}
